# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.spark_submit import SparkSubmitOperator
from jms.ods.etl.spmi.spmi_piece_bill import spmi_ods__spmi_piece_bill_load

executeDay = '{{ var.value.spmi_mark }}'
spmi_dwd__dwd_spmi_piece_bill_dt = SparkSubmitOperator(
    task_id='spmi_dwd__dwd_spmi_piece_bill_dt',
    email=['yushuo@jtexpress.com','yl_bigdata@yl-scm.com'],
    pool_slots=5,
    execution_timeout=timedelta(hours=2),
    name='spmi_dwd__dwd_spmi_piece_bill_dt_{{ execution_date | date_add(1) | cst_ds_nodash }}',
    driver_cores=4,
    driver_memory='8G',
    executor_cores=2,
    executor_memory='4G',
    num_executors=8,
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 208,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '2G',  # 堆外内存
          'spark.sql.shuffle.partitions': 6600,
          'spark.default.parallelism': 6600,
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 880,  # 每天生成 20 个分区
              'hive.exec.max.dynamic.partitions.pernode': 880,  # 每天生成 20 个分区
              },
    java_class='com.yunlu.bigdata.jobs.spmi.SpmiDwdCleanPiece01',  # spark 主类
    application='hdfs:///scheduler/jms/spark/chp/spmi/dwd/SpmiVolumeCostProfit.jar',
    application_args=['{{ execution_date | cst_ds }}',executeDay],  # 参数dt 2020-10-26
)


spmi_dwd__dwd_spmi_piece_bill_dt << spmi_ods__spmi_piece_bill_load
